package com.fxu.tpl.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fxu.framework.core.base.Cascade;
import com.fxu.framework.core.enums.EnumValid;
import com.fxu.framework.core.enums.StatusEnum;
import com.fxu.framework.core.sql.SEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.util.Date;

import static com.baomidou.mybatisplus.annotation.FieldFill.UPDATE;

/***
 * <p>fxu</p>
 * 操作日志表：[table_log]的数据实体类
 * @author fangxu
 * @version 2019-09-23
 ***/
@Data
@ApiModel(value = "TableLog", description = "表日志")
@TableName("fxu_table_log")
public class TableLog extends SEntity<TableLog> implements Serializable {
/*=== 自动生成代码 开始 ===*/
    private static final long serialVersionUID = 1508419363350827754L;

    @TableId(type = IdType.AUTO)
    @ApiModelProperty(value = "自增ID")
    private Long id;

    @ApiModelProperty(value = "项目ID", required = true)
    @NotNull(message = "项目ID必须赋值")
    private Long projectId;

    @ApiModelProperty(value = "表ID", required = true)
    @NotNull(message = "表ID必须赋值")
    private Long tableId;

    @TableField(select = false)
    @ApiModelProperty(value = "表数据JSON", required = true)
    @NotBlank(message = "表数据JSON必须赋值")
    @Size(max = 0, message = "表数据JSON的长度必须小于0位")
    private String tableJson;

    @TableField(select = false)
    @ApiModelProperty(value = "SQL执行语句", required = true)
    @NotBlank(message = "SQL执行语句必须赋值")
    private String sqlStr;

    @ApiModelProperty(value = "请求IP", required = true)
    @NotBlank(message = "请求IP必须赋值")
    private String requestIp;

    @ApiModelProperty(value = "表版本号")
    private Integer tableVersion;

    @ApiModelProperty(value = "创建时间")
    private Date createTime;

    @ApiModelProperty(value = "状态[1:正常,0:删除]")
    @EnumValid(target = StatusEnum.class, message = "状态的值必须为{1:正常,0:删除}")
    private Integer status;

    @TableField(fill = UPDATE, update = "%s+1")
    @ApiModelProperty(value = "版本号")
    private Integer version;

    @TableField(exist = false)
    @ApiModelProperty(value = "项目对象")
    @Cascade(thisField = "projectId", linkField = "id")
    private Project project;

    @TableField(exist = false)
    @ApiModelProperty(value = "表对象")
    @Cascade(thisField = "tableId", linkField = "id")
    private Table table;

    /** 获得状态的说明 */
    public String getStatusText() {
        return StatusEnum.desc(status);
    }
/*=== 自动生成代码 结束 ===*/
}
